﻿using AppWPF.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace AppWPF.ViewModels
{
    public class AgregarPacienteCommand : ICommand
    {

        Action<Paciente> action;
        Func<bool> canExecute;

        public AgregarPacienteCommand(Action<Paciente> Action) : this(Action, () => true) { }
        public AgregarPacienteCommand(Action<Paciente> Action, Func<bool> canExecute)
        {
            this.action = Action;
            this.canExecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            var persoma = parameter as Paciente;
            bool valor = !(persoma == null);

            return valor && this.canExecute();
        }

        public event EventHandler CanExecuteChanged;

        public void OnCanExecuteChanged()
        {
            if (CanExecuteChanged != null)
            {
                CanExecuteChanged(this, null);
            }
        }

        public void Execute(object parameter)
        {
            action(parameter as Paciente);
        }
    }
}
